package com.ujiuye.app;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

public class Demo2 {
    public static void main(String[] args) throws Exception {
        List<User> list = new ArrayList<>();
        //读取本地文件
        File file = new File("E:/dowload/demoxls.xlsx");

        XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(file));
        //获取第一个工作表
        XSSFSheet sheet = workbook.getSheetAt(0);
        //获取当前sheet页的总行数
        int rowNums = sheet.getPhysicalNumberOfRows();
        System.out.println(rowNums);
        for (int i=1;i<rowNums;i++){
            //获取行
            XSSFRow row = sheet.getRow(i);
            String username = row.getCell(0).getStringCellValue();
            String tel = row.getCell(1).getStringCellValue();
            list.add(new User(username,tel));
        }
        System.out.println(list);
    }
}
